<template>
  <div class="search">
      <el-autocomplete
           v-model="input"
           :fetch-suggestions="querySearch"
           clearable
           class="inline-input w-50"
           placeholder="请输入医院名称"
           :trigger-on-focus="false"
           @select="handleSelect"
         />
         <!--          -->
      <el-button type="primary" :icon="Search">搜索</el-button>
  </div>
</template>

<script setup lang='ts'>
import { ref } from 'vue'
import { Search } from "@element-plus/icons-vue";
import {reqHospitalInfo} from "@/api/home/index"
import type { HospitalInfo } from "@/api/home/types";
import { useRouter } from 'vue-router';

const querySearch=async (word:string,cb:(arg:any)=>void)=>{
  let result: HospitalInfo = await reqHospitalInfo(word);
  const list=result.data.map((item)=>({
    value:item.hosname,
    hoscode:item.hoscode
  }))
  cb(list)
}
let input=ref<string>("")

const router=useRouter()
const handleSelect=(item:any)=>{
router.push({path:"/hospital/register",query:{hoscode:item.hoscode}})
}

</script>

<script lang="ts">
export default {
    name:"Input"
}
</script>

<style scoped lang="scss">
.search {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 0px;

  ::v-deep(.el-input__wrapper) {
    width: 600px;
    margin-right: 10px;
  }
}
</style>
